package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.entity.Product;
import com.shop.mapper.ProductMapper;
import com.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author D
 * @since 2023-03-11 03:02:04
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Autowired
    ProductMapper productMapper;
    @Override
    public Page<Product> getPageList(Integer page, Integer pageSize, Integer typeId) {
        Page<Product> pages = new Page<>(page,pageSize);
        QueryWrapper<Product> bookQueryWrapper = new QueryWrapper<>();
        if (typeId != null && typeId != 0){
            bookQueryWrapper.eq("produce_type_id",typeId);
        }
        bookQueryWrapper.orderByDesc("created_time");

        return productMapper.selectPage(pages, bookQueryWrapper);
    }
}
